package design2.flyweight.example.forest;

import design2.flyweight.example.trees.Tree;
import design2.flyweight.example.trees.TreeFactory;
import design2.flyweight.example.trees.TreeType;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 绘制森林
 */
public class Forest extends JFrame {

	private List<Tree> trees=new ArrayList<>();

	public void plantTree(int x, int y, String name, Color color,String otherTreeData){
		TreeType treeType= TreeFactory.getTreeType(name, color, otherTreeData);
		Tree tree=new Tree(x,y,treeType);
		trees.add(tree);
	}

	@Override
	public void paint(Graphics g) {
		for (Tree tree : trees) {
			tree.draw(g);
		}
	}
}
